import {http} from "@/utils/http/axios";
import {storage} from '@/utils/Storage';

export function saveProblem(name, time, memo, diff, source, content) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/problem',
    headers: {token: storage.get('token')},
    method: 'POST',
    params: {
      name: name,
      timeLimit: time,
      memoLimit: memo,
      difficulty: diff,
      source: source,
      content: content,
    },
  });
}

export function deleteProblem(id) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/problem?id=' + id,
    headers: {token: storage.get('token')},
    method: 'DELETE',
  });
}

export function updateProblem(id, name, time, memo, diff, source, content, status, cases) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/problem',
    headers: {token: storage.get('token')},
    method: 'PUT',
    params: {
      id: id,
      status: status,
      name: name,
      timeLimit: time,
      memoLimit: memo,
      difficulty: diff,
      source: source,
      content: content,
      cases: cases,
    },
  });
}

export function problemPage(params) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/problem/page',
    headers: {token: storage.get('token')},
    method: 'POST',
    params,
  });
}

export function caseList(projectId) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/case/list?projectId=' + projectId,
    headers: {token: storage.get('token')},
    method: 'GET',
  });
}
